package com.atguigu.activemq.transaction;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

//消息消费者编码
public class JmsConsumer_TX {
    public static final String ACTIVEMQ_URL="tcp://124.70.84.192:61616";
    public static final String QUEUE_NAME="queue_lemon";
    //先写死连接地址,tcp协议，以“tcp://”开头，端口号写后端进程端口号
    public static void main(String[] args) throws Exception {
        ActiveMQConnectionFactory activeMQConnectionFactory=new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = activeMQConnectionFactory.createConnection();
        connection.start();
        Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(QUEUE_NAME);
        MessageConsumer messageConsumer = session.createConsumer(queue);
        System.out.println("2号消费者");
        while (true){
            TextMessage textMessage= (TextMessage)messageConsumer.receive(3000L);
            if(null!=textMessage){
                String c01 = textMessage.getStringProperty("c01");
                int vip = textMessage.getIntProperty("vip");
                boolean vip8 = textMessage.getBooleanProperty("vip8");
                //textMessage.setByteProperty(...);
                System.out.println(textMessage.getText()+";"+c01+";"+vip+";"+vip8);
//                textMessage.acknowledge();
            }else {
                break;
            }
        }
        session.commit();
        messageConsumer.close();
        session.close();
        connection.close();
    }
}
